<template>
  <svg :class="svgClass" aria-hidden="true">
    <use :xlink:href="iconName" style="width: 20px; height: 20px" />
  </svg>
</template>

<script>
// icon组件
export default {
  name: "SvgIcon",
  props: {
    iconClass: {
      type: String,
      required: true,
    },
    className: {
      type: String,
      default: "",
    },
  },
  computed: {
    iconName() {
      return `#icon-${this.iconClass}`;
    },
    svgClass() {
      if (this.className) {
        return "svg-icon " + this.className + " svg-icon-with-margin"; // 添加新的类名
      } else {
        return "svg-icon svg-icon-with-margin"; // 添加新的类名
      }
    },
  },
  mounted() {
    // 可选：添加调试信息
    console.log(`SvgIcon mounted: ${this.iconName}`);
  },
};
</script>

<style scoped>
.svg-icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  min-width: 14px; /* 设置最小尺寸 */
  min-height: 14px; /* 设置最小尺寸 */
  overflow: hidden;
  color: red; /* 临时添加，用于调试 */
}
.svg-icon.large {
  width: 24px;
  height: 24px;
}
/* 确保SVG内部路径继承颜色 */
.svg-icon use {
  fill: currentColor;
}
/* 定义新的类名，设置右边距为8px */
.svg-icon-with-margin {
  /* margin-right: 8px; */
}
.svg-icon svg-icon-with-margin {
  width: 14px;
  height: 14px;
}
</style>
